﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Sayook.Framework.Tools
{
    /// <summary>
    /// 反射工具
    /// </summary>
    public static class ReflectionHelper
    {
        /// <summary>
        /// 获取公共属性名称
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static IEnumerable<string> GetPublicProperties<T>()
        {
            Type type = typeof(T);
            PropertyInfo[] propertyInfos = type.GetProperties();
            return propertyInfos.Select(x => x.Name);
        }

        /// <summary>
        /// 获取公共属性名称
        /// 但过滤的某自定义属性
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="attributeType">自定义属性</param>
        /// <returns></returns>
        public static IEnumerable<string> GetPublicPropertiesByFilterCustomAttributes<T>(Type attributeType)
        {
            Type type = typeof(T);
            PropertyInfo[] propertyInfos = type.GetProperties();
            return propertyInfos.Where(x => !x.GetCustomAttributes(attributeType).Any()).Select(x => x.Name);
        }
    }
}